// To change this License template, choose Tools / Templates
// and edit Licenses / FanDefaultLicense.txt
//
// History:
//   07.09.2010 JSTAUDEMEYER Creation
//

using [java] javax.sound.midi
using [java] javax.sound.midi::Sequence as MidiSequence
using [java] java.lang::Thread
**
** SimplePlayer
**
class SimplePlayer
{
	// Midi meta event
	static const Int END_OF_TRACK_MESSAGE := 47

    private Sequencer sequencer

	/**
	 * Creates a new MidiPlayer object.
	 *
	 * @throws MidiUnavailableException
	 */
	new make() {
		sequencer = MidiSystem.getSequencer()
		sequencer.open();
	}


	Void play(MidiSequence sequence) {
		sequencer.setSequence(sequence)
		sequencer.start
		while (sequencer.isRunning()) {
			echo("<"+sequencer.getMicrosecondPosition()/1000+">")
			try {
				Thread.sleep(1000);
			} catch {
				//
			}
		}
	}

}

